<?php
include("config.php");
if (isset($_REQUEST["id"]) && isset($_REQUEST["p"])) {
	
	$db_www = new DB($server_username,$server_pass,$server_db,$server,$driver);
	
	if ($db_www->isConnected()) {							
		$get_username = addslashes_mssql($_REQUEST["id"]);
		$get_password = addslashes_mssql($_REQUEST["p"]);
		$auto_query = str_replace("<get_username>", $get_username, $auto_query);		
		$info = $db_www->returnInfo($auto_query);									
		if (!empty($info)) {
			$pass = md5(trim($info["r05_pareigos"]));
			if (strtoupper($pass) == strtoupper ($get_password)) {
		
				$_SESSION['user'] = $info["r05_kodas_rs"];
                $_SESSION['group'] = trim($info["grupe"]);

				$i_query = str_replace("<kodas>", $_SESSION['user'], $i_query);
				$minfo = $db_www->returnInfo($i_query);		
				$_SESSION['discount'] = trim($minfo["N08_kodas_ls_6"]);

				$_SESSION['company'] = @iconv('windows-1257', 'UTF-8', $minfo["N08_PAV"]);
				if (!isset($_SESSION["auser"])) {
					logAction($_SESSION["user"],6);
				} else {
					logAction("Administratorius ". $_SESSION["auser"],6);
				}
				header('Location: accounts.php');
			} else {
				include("header.php");		
			?>						
					<p>Blogas vartotojo vardas ar slaptažodis.</p>
			<?php
				logActionLong($get_username,"","Blogas slaptažodis:" . $get_password,8);
			}
		} else {
			include("header.php");		
		?>						
				<p>Blogas vartotojo vardas ar slaptažodis.</p>
		<?php
			logActionLong($get_username,"","Blogas slaptažodis:" . $get_password,6);
		}
	} else {
			include("header.php");	
		?>						
				<p>Klientų aptarnavimo sistema laikinai neveikia. <A href="index.php">Bandykite vėliau</A></p>
		<?php							
	}	
} else {
		include("header.php");	
		?>						
				<p>Sistemos klaida</p>
		<?php
}
?>